#exam6.6CalHlm.py  红楼梦人物统计
import jieba
hlmTxt = open("D:/红楼梦.txt", "r", encoding="utf-8").read()
words = jieba.lcut(hlmTxt)
counts = {}
excludes= {"什么","一个","我们","那里","如今","你们"}
for word in words:
    if len(word) == 1:
        continue
    else:
        counts[word] = counts.get(word,0) + 1
for word in excludes:
    del(counts[word])
items = list(counts.items())
items.sort(key= lambda x:x[1],reverse=True)
for i in range(10):
    word,count = items[i]
    print("{:<10}{:>5}".format(word,count))
